$(function() {
			if ($("#hasItems").val() == "no") {
				orderConfirmTip("您目前购物车内没有商品，您可再去逛逛");
			}

			$("#chk_needInvoice").click(function() {
						if ($(this).attr("checked") == "checked") {
							$("#needInvoice").val(2);
							$("#table_invoice").show();
							$("#span_invoice_money_info").show();
							$("#total_money_add_invoice").show();
							$("#total_money_no_invoice").hide();
						} else {
							$("#needInvoice").val(1);
							$("#table_invoice").hide();
							$("#span_invoice_money_info").hide();
							$("#total_money_add_invoice").hide();
							$("#total_money_no_invoice").show();
						}
					});

			$("input:text").change(function() {
						if (trimAllSpace(($(this).val())))
							$(this).next("span.clrd").empty().hide();
					});

			$("#btn_submit").click(function() {	
						// 检查购物车是否有变动
						$.post("mall/cart/verify", {
									preTotalItems : $("#totalItems").val()
								}, function(data) {
									if (data.result == 1) {
										orderConfirmTip("您目前购物车内没有商品，您可再去逛逛");
									} else if (data.result == 2) {
										orderConfirmTip("您的购物车发生变化，请再次确认");
									} else if (data.result == 3) {
										orderConfirmTip("系统异常，请稍候再试");
									} else {
										if ($("#chk_needInvoice").attr("checked") == "checked") {
											// 验证发票数据是否正确填写
											if (!verifyInvoice("invoiceTitle,consignee,msisdn,address"))
												return false;
											if(!isMobilePhone($("#msisdn").val()))
											{
												$("#msisdn").next("span.clrd").empty().html($("#msisdn").attr("title")+"格式不正确").show();
												$("#msisdn").focus();
												return false;
											}
											if($("#zipCode").val()!=""&&!IsPostId($("#zipCode").val()))
											{
												$("#zipCode").next("span.clrd").empty().html($("#zipCode").attr("title")+"格式不正确").show();
												$("#zipCode").focus();
												return false;
											}
										}
										$(this).attr("disabled", true);
										$("#orderForm").submit();
									}
								});
					});
		});

function orderConfirmTip(tipContent) {
	var list = art.dialog.list;
	for (var i in list) {
		list[i].close();
	}
	art.dialog({
				title : "提示",
				content : tipContent,
				icon : "warning",
				drag : true,
				lock : true,
				esc : false,
				okVal : "返回购物车",
				cancelVal : "先看看其他商品",
				ok : function() {
					window.location.href = getRootUrl()+"mall/cart/index";
				},
				cancel : function() {
					window.location.href = getRootUrl()+"mall/index";
				}
			});
}

function verifyInvoice(fieldIds) {
	var ids = fieldIds.split(",");
	for (var i = 0; i < ids.length; i++) {
		var jqId = "#" + ids[i];
		if ($(jqId).length <= 0)
			continue;
		var val = trimAllSpace(($(jqId).val()));
		$(jqId).val(val);
		if (!val) {
			$(jqId).focus();
			$(jqId).next("span.clrd").empty().html("请输入" + $(jqId).attr("title")).show();
			return false;
		}
	}
	return true;
}